package com.hxd.otc.module.fiat_deal.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseFragment;
import com.hxd.otc.module.fiat_deal.contract.SilverDealContract;
import com.hxd.otc.module.fiat_deal.presenter.SilverDealPresenter;
import com.hxd.otc.widget.DealTitleBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 包  名 :  com.hxd.otc.module.deal.fragment
 * 类  名 :  SilverDealFragment
 * 作  者 :  胡庆岭
 * 时  间 :  2018/6/13 10:18
 * 描  述 :  ${TODO}
 */
public class SilverDealFragment extends BaseFragment<SilverDealPresenter> implements SilverDealContract.View {

    @BindView(R.id.deal_title_bar)
    DealTitleBar mDealTitleBar;
    @BindView(R.id.tab_layout)
    TabLayout mTabLayout;
    @BindView(R.id.recycler_view)
    RecyclerView mRecyclerView;
    @BindView(R.id.smart_refresh_layout)
    SmartRefreshLayout mSmartRefreshLayout;
    @BindView(R.id.team_cv)
    CardView mTeamCardView;
    @BindView(R.id.card_parent_ll)
    LinearLayout mCardParentGroup;
    @BindView(R.id.screen_card_view)
    CardView mScreenCardView;
    @BindView(R.id.parent_screen_ll)
    LinearLayout mParentScreenGroup;
    @BindView(R.id.screen_cb)
    CheckBox mScreenCheck;


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_silver_deal;
    }

    @Override
    protected void initView() {

        initTabView();
        if (getContext() != null) {
            String[] tabTitleArray = getContext().getResources().getStringArray(R.array.silver_deal_title_array);
            if (tabTitleArray.length > 0) {
                for (int i = 0; i < tabTitleArray.length; i++) {
                    View inflate = getLayoutInflater().inflate(R.layout.weight_deal_tab_item, mTabLayout, false);
                    mTabLayout.addTab(mTabLayout.newTab().setCustomView(inflate));
                    TextView textView = inflate.findViewById(R.id.deal_status_tv);
                    textView.setText(tabTitleArray[i]);
                    View line = inflate.findViewById(R.id.indicator_view);
                    TabLayout.Tab tabAt = mTabLayout.getTabAt(i);
                    if (tabAt != null) {
                        line.setBackgroundColor(tabAt.isSelected() ? ContextCompat.getColor(getContext(), R.color.color_text1) :
                                ContextCompat.getColor(getContext(), R.color.transparent));
                    }

                }

            }
        }
    }

    /**
     * 初始化TabLayoutTitle
     */
    private void initTabView() {

    }


    @Override
    protected void initData() {
       /* List<DealTeamBean> data = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            DealTeamBean bean = new DealTeamBean();
            bean.height = DataUtils.dp2px(getContext(), 35);
            bean.width = DataUtils.dp2px(getContext(), 105);
            data.add(bean);
        }
        UIUtils.addTeamView(mTeamCardView, data);
        UIUtils.addTeamView(mScreenCardView,data);*/
    }

    @Override
    protected void initEvent() {
        mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab.getCustomView() != null && getContext() != null) {
                    tab.getCustomView().findViewById(R.id.indicator_view).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.color_text1));
                }

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                if (tab.getCustomView() != null && getContext() != null) {
                    tab.getCustomView().findViewById(R.id.indicator_view).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.transparent));
                }
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        mDealTitleBar.setOnCheckTitleListener(new DealTitleBar.OnCheckTitleListener() {
            @Override
            public void onCheckChanged(boolean isCheck) {
                mCardParentGroup.setVisibility(isCheck ? View.VISIBLE : View.GONE);
            }

            @Override
            public void onRightClick(View v) {

            }
        });

        mScreenCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mParentScreenGroup.setVisibility(isChecked ? View.VISIBLE : View.GONE);
                mDealTitleBar.setAllClickStatus(isChecked);
            }
        });
    }

    @Override
    protected SilverDealPresenter createPresenter() {
        return new SilverDealPresenter(this);
    }


    @OnClick({R.id.parent_screen_ll, R.id.card_parent_ll})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.parent_screen_ll:
                mParentScreenGroup.setVisibility(View.GONE);
                mScreenCheck.setChecked(false);
                break;
            case R.id.card_parent_ll:
                mCardParentGroup.setVisibility(View.GONE);
                mDealTitleBar.mQueuesCheck.setChecked(false);
                break;
        }
    }

}
